package com.skytech.component.crawler.scratch.downloader;

import com.gargoylesoftware.htmlunit.WebClient;

public class WebClientUtil {
    private static WebClient wc;
    static {
        wc = new WebClient();
        wc.getOptions().setJavaScriptEnabled(true); //启用JS解释器，默认为true
        wc.getOptions().setCssEnabled(false); //禁用css支持
        wc.getOptions().setThrowExceptionOnScriptError(false); //js运行错误时，是否抛出异常
        wc.waitForBackgroundJavaScript(30000);
        wc.waitForBackgroundJavaScriptStartingBefore(30000);
        wc.getOptions().setTimeout(30001);
        wc.addRequestHeader("User-Agent","Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.62 Safari/537.36");
    }

    public static WebClient getWebClient(){
        return wc;
    }
}
